package com.aishua.aishuawallet.mina;

import android.content.Context;

import com.aishua.aishuawallet.Constant;
import com.aishua.aishuawallet.utils.LogUtils;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class MianManager {

    private ExecutorService mThreadPool = null;
    private static MianManager manager = new MianManager();

    private  ConnectionManager mManager;

    private MianManager() {

        if (null == mThreadPool) {
            mThreadPool = Executors.newFixedThreadPool(1);
        }
    }

    public static MianManager getManager() {

        return manager;
    }

    /**
     * ==============================判断是否绑定过==============================
     */
    public void request(Context mContext, String requestString, MinaResultLIstener minaResultLIstener) {


        LogUtils.v("MianManager===request"+requestString);
        ConnectionConfig config = new ConnectionConfig.Builder(mContext)
                .setIp(Constant.SOCKET_IP)
                .setPort(Constant.SOCKET_PORT)
                .setReadBufferSize(10240)
                .setConnectionTimeout(10000).builder();

        mManager = new ConnectionManager(config, minaResultLIstener);

        Task task = new Task(mContext, requestString, mManager);
        executeTask(task);

    }

    public void executeTask(Runnable runnable) {

        mThreadPool.submit(runnable);
    }

    public void shutDown(){

        mManager.disContect();

    }


}
